﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Entities;
using ExpertMIS.Brokers;
using System.Collections;

namespace ExpertMIS.Admin.UserControl
{
    public partial class BulletinForm : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public BulletinEntity Entity
        {
            get
            {
                return ViewState["_BulletinEntity_"] as BulletinEntity;
            }
            set
            {
                ViewState["_BulletinEntity_"] = value;
            }
        }

        public void LoadBulletin(string BulletinOID)
        {
            BulletinBroker broker = new BulletinBroker();

            Hashtable htQuery = new Hashtable();
            htQuery["OID"] = BulletinOID;
            Entity = broker.GetEntity(htQuery) as BulletinEntity;

            if (Entity == null)
            {
                Entity = broker.NewEntity() as BulletinEntity;
            }
            else
            {
                txBulletin.Text = Entity.Bulletin;
                txAbstract.Text = Entity.Abstract;
                txContext.Text = Entity.Context;
                chkEnabled.Checked = Entity.Enabled;
                txSort.Text = Entity.Sort.ToString();
                ddlBulletinZone.SelectedValue = Entity.BulletinZone;
                lblStamp.Text = string.Format("编写日期:{0}|更新日期:{1}", Entity.CreateDate, Entity.UpdateDate);
            }
        }

        public bool SaveBulletin()
        {
            try
            {
                BulletinBroker broker = new BulletinBroker();

                Entity.Bulletin = txBulletin.Text;
                Entity.Abstract = txAbstract.Text;
                Entity.Context = txContext.Text;
                int iSort = 0;
                int.TryParse(txSort.Text, out iSort);
                Entity.Sort = iSort;
                Entity.Enabled = chkEnabled.Checked;
                Entity.BulletinZone = ddlBulletinZone.SelectedValue;

                broker.SaveEntity(Entity, null);
                lblStamp.Text = string.Format("编写日期:{0}|更新日期:{1}", Entity.CreateDate, Entity.UpdateDate);

                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}